//============================================================================
// Name        : DocumentFeatures.cpp
// Author      : lucmir@dcc.ufmg.br
// Description :
//============================================================================

#include "DocumentFeatures.h"


DocumentFeatures::DocumentFeatures() {

}

DocumentFeatures::~DocumentFeatures() {

}

bool DocumentFeatures::readPageRanks(std::string inFileName) {
	std::ifstream file;
	std::string line;
	unsigned int docId;
	double pageRank;

	file.open(inFileName.c_str());
	if (!file.is_open()) {
		std::cout << "\nERRO: Não foi possível abrir o arquivo: \"" << inFileName << "\"\n\n";
		return false;
	}
	while(!file.eof()) {
		getline(file, line);
		std::istringstream istr(line);
		istr >> docId;
		istr >> pageRank;
		this->pageRanks[docId] = pageRank;
	}
	file.close();

	return true;
}

double DocumentFeatures::getPageRank(unsigned int docId) {
	std::map<unsigned int, double>::iterator itr;
	itr = this->pageRanks.find(docId);
	if ( itr == this->pageRanks.end() ) {
		return 0.0;
	}
	return itr->second;
}

bool DocumentFeatures::readAnchorTexts(std::string inFileName) {
	return this->anchorText.readFromFile(inFileName);
}

unsigned int DocumentFeatures::containsAnchorText(unsigned int termId, unsigned int docId) {
	return this->anchorText.containsTerm(termId, docId);
}

